import 'package:flutter/material.dart';

class GesturePage extends StatefulWidget {
  @override
  _GesturePageState createState() => _GesturePageState();
}

class _GesturePageState extends State<GesturePage> {
  String printString='';
  double moveX=0,moveY=0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('如何检测用户手势以及处理点击事件'),
      ),
      body: FractionallySizedBox(
        widthFactor: 1,
        child: Stack(
          children: <Widget>[
            Column(
              children: <Widget>[
                GestureDetector(
                  onTap: ()=>_printMsg('点击'),
                  onDoubleTap: ()=>_printMsg('双击'),
                  onLongPress: ()=>_printMsg('长按'),
                  onTapCancel: ()=>_printMsg('取消'),
                  onTapUp: (e)=>_printMsg('松开'),
                  onTapDown: (e)=>_printMsg('按下'),
                  child:Container(
                    padding: EdgeInsets.all(60),
                    decoration: BoxDecoration(
                      color: Colors.lightBlue
                    ),
                    child: Text(
                      '点我',
                      style: TextStyle(
                        fontSize: 36.0,
                        color: Colors.white
                      ),
                    ),
                  ) ,
                ),
                Text(printString),
              ],
            ),
            Positioned(
              left: moveX,
              top: moveY,
              child: GestureDetector(
                onPanUpdate: (e)=>_doMove(e),
                child: Container(
                  width: 72.0,
                  height: 72.0,
                  decoration: BoxDecoration(
                    color: Colors.amber,
                    borderRadius: BorderRadius.circular(36.0),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  _printMsg(String msg) {
    setState(() {
      printString+=',$msg';
    });
  }

  _doMove(DragUpdateDetails e) {
    setState(() {
      moveY+=e.delta.dy;
      moveX+=e.delta.dx;
    });
    print(e);
  }
}
